package pl.koziolekweb.translator.gui;

import java.awt.Container;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SpringLayout;

import pl.koziolekweb.translator.utilites.Context;

/**
 * 
 * @author Bartlomiej Kuczyński
 * 
 * 
 *         $Id: MainFrame.java 157 2009-03-12 14:27:06Z bjkuczynski $
 */
public class MainFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6522670033610357630L;

	/**
	 * 
	 */
	private Context context;

	private SpringLayout layout;

	private JPanel translator;

	public MainFrame(final Context context) {
		this.context = context; // kontekst
		initFrameParameters(); // ustawienia tej ramki
		addComponents();

	}

	private void addComponents() {
		Container container = getContentPane();

		translator = new TranslatorPanel(context);

		container.add(translator);
		layout.putConstraint(SpringLayout.NORTH, translator, 3,
				SpringLayout.NORTH, container);
		layout.putConstraint(SpringLayout.WEST, translator, 3,
				SpringLayout.WEST, container);
		layout.putConstraint(SpringLayout.EAST, translator,
				(int) (getWidth() * 0.4), SpringLayout.WEST, container);
		layout.putConstraint(SpringLayout.SOUTH, translator, container
				.getHeight() - 3, SpringLayout.SOUTH, container);

		WorkingArea workingArea = new WorkingArea(context);
		container.add(workingArea);

		layout.putConstraint(SpringLayout.NORTH, workingArea, 3,
				SpringLayout.NORTH, container);

		layout.putConstraint(SpringLayout.WEST, workingArea, 50,
				SpringLayout.EAST, translator);
		layout.putConstraint(SpringLayout.EAST, workingArea, -3,
				SpringLayout.EAST, container);
		layout.putConstraint(SpringLayout.SOUTH, workingArea, container
				.getHeight() - 3, SpringLayout.SOUTH, container);
	}

	private void initFrameParameters() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setResizable(false);
		setSize(Integer.parseInt(context.getParam("width")), Integer
				.parseInt(context.getParam("height")));
		layout = new SpringLayout();
		setLayout(layout);
	}

}
